package com.example.databasetest;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

//
public class MyDbHelper extends SQLiteOpenHelper
{
//SQLiteOpenHelper是一个抽象类，

    public MyDbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table book(id integer primary key autoincrement, author varchar(40), price real," +
                " pages int,name text)");

        Log.i("my", "book表创建成功");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if(oldVersion<2) {
            db.execSQL("create table category(id integer primary key autoincrement, name text)");
        }
        Log.d("my", String.valueOf(oldVersion));
        Log.d("my", "这里是升级的地方");
    }
}
